#!/usr/bin/evn python
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   文件名称 :     sinleton
   文件功能描述 :   功能描述
   创建人 :       小钟同学
   创建时间 :          2021/12/6
-------------------------------------------------
   修改描述-2021/12/6:         
-------------------------------------------------
"""
import threading


class Singleton(type):
    _instances = {}
    _locks = {}
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            if cls.__name__ not in cls._locks:
                cls._locks[cls.__name__] = threading.Lock()

            with cls._locks[cls.__name__]:
                if cls not in cls._instances:
                    cls._instances[cls] = super(Singleton, cls).__call__(
                        *args, **kwargs
                    )
        return cls._instances[cls]

def SingletonCls(cls):
    _instance = {}

    def _singleton(*args, **kargs):
        if cls not in _instance:
            _instance[cls] = cls(*args, **kargs)
        return _instance[cls]

    return _singleton